Modern PHP by Josh Lockhart

Modern PHP by Josh Lockhart

Author:Josh Lockhart [Lockhart, Josh]
Language: eng
Format: epub
Tags: php, o'reilly
Publisher: O'Reilly Media, Inc.
Published: 0101-01-01T00:00:00+00:00


Example 5-38. Catch thrown exception

<?php try { $pdo = new PDO('mysql://host=wrong_host;dbname=wrong_name'); } catch (PDOException $e) { // Inspect the exception for logging $code = $e->getCode(); $message = $e->getMessage(); // Display a nice message to the user echo 'Something went wrong. Check back soon, please.'; exit; }

You can use multiple catch blocks to intercept multiple types of exceptions. This is useful if you need to act differently based on the type of exception thrown. You can also use a finally block to always run a block of code after you catch any exception (Example 5-39).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.